package com.resou.reader.mine.adapter;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.resou.reader.R;
import com.resou.reader.api.entry.CouponBean;
import com.resou.reader.reader.manager.BookStatus;
import com.resou.reader.utils.DateUtil;
import com.resou.reader.utils.DateUtils;

import java.util.List;

/**
 * Author: 萤火虫
 * E-mail:  Allensuns@163.com
 * Description:
 * CreateTime: 2019-03 -18
 **/
public class CouponAdapter extends BaseQuickAdapter<CouponBean, BaseViewHolder> {
    private int type = 0;//0可使用  1使用完  2：已过期

    public CouponAdapter(int layoutResId, @Nullable List<CouponBean> data) {
        super(layoutResId, data);
    }

    public CouponAdapter(@Nullable List<CouponBean> data) {
        super(data);

    }

    public CouponAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, CouponBean item) {

        helper.addOnClickListener(R.id.llCouponOnclick);
        helper.setText(R.id.tvHotTicket, item.getObtain_voucher() + "");
        helper.setText(R.id.tvResidue, "剩余" + item.getSurplus_voucher() + "热券");
        helper.setText(R.id.tvValidTime, "有效期至：" + DateUtils.transferLongToDate("yyyy-MM-dd  HH:mm", item.getExpire_time()));
        //TODO  已经沟通过，后台让写死 暂无其他扣除方式
//        helper.setText(R.id.tvMethod, item.getObtain_source() + "");
        helper.setText(R.id.tvSource, "来源：" + item.getObtain_source() + "");
        helper.setText(R.id.tvPastDueTime, "还有" + DateUtils.getDateDay(item.getExpire_time()) + "天过期");
        switch (type) {
            case 0:
                helper.getView(R.id.llContent).setBackgroundColor(mContext.getResources().getColor(R.color.color_ffd53d2d));
                helper.getView(R.id.tvPastDueTime).setVisibility(View.VISIBLE);
                break;
            case 1:
                helper.getView(R.id.llContent).setBackgroundColor(mContext.getResources().getColor(R.color.color_E89C94));
                helper.getView(R.id.tvPastDueTime).setVisibility(View.GONE);
                break;
            case 2:
                helper.getView(R.id.llContent).setBackgroundColor(mContext.getResources().getColor(R.color.CCCCCC));
                helper.getView(R.id.tvPastDueTime).setVisibility(View.GONE);
                break;

        }
    }


    /**
     * 加载数据
     *
     * @param couponBeans
     * @param type
     */
    public void addCoupontData(List<CouponBean> couponBeans, int type) {
        this.type = type;
        addData(couponBeans);
    }

}
